package main

import (
	"flag"
	"fmt"
	"os"
)

// 实际中应该用更好的变量名
var (
	h bool
	v bool
	s string
	p string
	q *bool
	n *string
)

func init() {
	// 默认h的值为false, 如果加了'-h', h就置为true
	flag.BoolVar(&h, "h", false, "this help")
	flag.BoolVar(&v, "v", false, "show version and exit")
	// 带上"-s shuoGG"则s值为shuoGG, 否则为jjj
	flag.StringVar(&s, "s", "jjj", "send `signal` to a master process: stop, quit, reopen, reload")
	flag.StringVar(&p, "p", "/usr/local/nginx/", "set `prefix` path")
	// 另一种绑定方式
	q = flag.Bool("q", false, "suppress non-error messages during configuration testing")
	n = flag.String("n", "I am N", "input the str after -n")
	// 改变默认的 Usage
	flag.Usage = usage
}

func main() {
	flag.Parse()
	println(s)
	if h {
		flag.Usage()
	}
}

func usage() {
	fmt.Fprintf(os.Stderr, `Usage: nginx [-hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives]\n)`)
	flag.PrintDefaults()
}
